<template>
	<view class="index">
		<view class="search-wrapper">
			<view class="label">
				供货日期：
			</view>
			<!-- <uni-datetime-picker ref="dateTime" v-model="range" @change="changeDateByRange" type="daterange">
				<text>{{startDate}}</text>
				<text style="margin: 0 20rpx;">至</text>
				<text>{{endDate}}</text>
				<uni-icons type="calendar-filled" class="icon" color="#898989" size="18"></uni-icons>
			</uni-datetime-picker> -->
			<uni-datetime-picker @change="changeDate" type="date" v-model="single">
				<text>{{ dateStr }}</text>
				<uni-icons type="bottom" size="14" class="icon" color="#666666"></uni-icons>
			</uni-datetime-picker>
		</view>
		<mescroll-uni ref="mescrollRef" height="100%" @init="mescrollInit" bottom="80" :down="downOption"
			@down="downCallback" :up="upOption" @up="upCallback">
			<!-- 数据列表 -->
			<view class="item" v-for="(item,index) in list" :key="index">
				<supplyItem :source="item" :index="index"></supplyItem>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import supplyItem from "@/subPage_entrucking/supplyItem";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption: {
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: true, // 不自动加载
					textNoMore: '没有更多啦~',
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						fixed: true,
						top: '200upx',
						tip: '~ 空空如也 ~', // 提示
						icon: 'https://sm.hobon.cc/static/hobon_noorder.png',
						zIndex: 1
					}
				},
				isLoading: true,
				list: [],
				pageNum: 1,
				pageSize: 10,
				keywords: '',
				supplyDate: '',
				single: this.$helper.getDay(0, '-'),
				// startDate: this.$helper.getDay(-29, '-'),
				// endDate: this.$helper.getDay(1, '-'),
				// range: [this.$helper.getDay(-29, '-'), this.$helper.getDay(1, '-')],
			}
		},
		onLoad(option) {
			// if (option.keywrods) {
			// 	this.keywords = option.keywrods;
			// 	this.supplyDate = option.supplyDate;
			// }
			console.log("this.userInfo", this.userInfo)
		},
		computed: {
			dateStr() {
				let str = '';
				if (this.single === this.$helper.getDay(0, '-')) {
					str += '今天 ';
				} else if (this.single === this.$helper.getDay(-1, '-')) {
					str += '昨天 ';
				} else if (this.single === this.$helper.getDay(-2, '-')) {
					str += '前天 ';
				} else if (this.single === this.$helper.getDay(1, '-')) {
					str += '明天 ';
				}
				str += this.single.substring(5);
				return str;
			},
			userInfo() {
				return this.$store.state.userInfo
			}
		},
		methods: {
			changeDate() {
				this.downCallback()
			},
			changeDateByRange(e) {
				this.startDate = e[0];
				this.endDate = e[1];
				this.downCallback()
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				//let status = ['1', '2', '10', '11', '3']
				this.pageNum = page.num;
				const params = {
					pickupPointName: '',
					supplyDate: this.single,
					supplyWarehouseId: this.userInfo.supplyWarehouseId,
					//supplierId: this.$store.state.userInfo.supplierInfo.id,
					//supplyDateEnd: this.endDate,
					//supplyDateStart: this.startDate,
				};
				const data = await this.$api.post('/adm/supply/record/citySupplyList', params, false)
				if (data.code === 200) {
					this.isLoading = false;
					if (this.pageNum === 1) {
						this.list = [];
					}
					let arr = [];
					data.data.forEach((item) => {
						if (item.schemaCaption.indexOf("提前") > -1) {
							item.schemaCaption = item.schemaCaption.replace("(提前)", "");
						}
						let index = arr.findIndex(
							(row) =>
							row.pickupPointId === item.pickupPointId &&
							item.schemaCaption.indexOf(row.schemaCaption) > -1
						);
						if (index === -1) {
							arr.push(item);
						} else {
							arr[index].quantity =
								parseFloat(arr[index].quantity) + parseFloat(item.quantity);
							arr[index].pendingProductQuantity =
								parseFloat(arr[index].pendingProductQuantity) +
								parseFloat(item.pendingProductQuantity);
							arr[index].pendingQuantity =
								parseFloat(arr[index].pendingQuantity) +
								parseFloat(item.pendingQuantity);
							arr[index].itemList.push(...item.itemList);
						}
						//item.supplyDate = formatDate(item.supplyDate);
					});
					this.list = this.list.concat(arr);
					this.mescroll.endBySize(arr.length, 1);
				} else {
					this.mescroll.endErr();
				}
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			openPic(index, urls) {
				uni.previewImage({
					urls: urls,
					current: index
				});
			},
			scan() {
				uni.scanCode({
					scanType: ["qrCode"],
					success: async (res) => {
						console.log(res)
						if (res.result.indexOf('code') > -1) {
							const code = JSON.parse(res.result).code;
							uni.navigateTo({
								url: '/subPage_receiptOrder/receipt?code=' + code
							})
						} else {
							uni.showToast({
								title: '无效的回单码',
								icon: 'error'
							})
						}
					}
				});
			}
		},
		components: {
			supplyItem
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;

		.search-wrapper {
			background-color: #ffffff;
			margin: 3upx 0;
			padding: 0upx 30upx;
			position: relative;
			display: flex;
			align-items: center;
			line-height: 32rpx;
			height: 80rpx;
			font-size: 32rpx;


			.label {
				margin-right: 10rpx;
				font-size: 32rpx;
			}

			.icon {
				margin-left: 20rpx;
			}
		}

		.item {
			margin: 20upx;
			border-radius: 20upx;
			background-color: #ffffff;
			overflow: hidden;

			.supplier-wrapper {
				padding: 20upx 30upx;
				background-color: #F5F6FA;

				.supplier-info {
					display: flex;
					align-items: center;
					margin-bottom: 10upx;
				}

				.supplier-address {
					font-size: 30upx;
					color: #666666;
				}

				.name {
					flex: 1;
					font-size: 34upx;
					//width: 500rpx;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden; //溢出内容隐藏
					text-overflow: ellipsis; //文本溢出部分用省略号表示
					display: -webkit-box; //特别显示模式
					-webkit-line-clamp: 1; //行数
					line-clamp: 1;
					-webkit-box-orient: vertical; //盒子中内容竖直排列
					font-weight: bold;
					color: #343434;
				}

				.tel {
					font-size: 32upx;
					color: #343434;
				}
			}

			.product-info {
				overflow: hidden;
				padding: 0 30upx;

				.productName-wrapper {
					margin-top: 20upx;
					display: flex;
					align-items: center;

					.productName {
						flex: 1;
						font-size: 32upx;
						line-height: 38upx;
						//width: 500rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden; //溢出内容隐藏
						text-overflow: ellipsis; //文本溢出部分用省略号表示
						display: -webkit-box; //特别显示模式
						-webkit-line-clamp: 2; //行数
						line-clamp: 2;
						-webkit-box-orient: vertical; //盒子中内容竖直排列
						font-weight: bold;
						color: #464646;
					}
				}

				.info-wrapper {
					display: flex;
					align-items: center;
					margin-top: 15upx;
					font-size: 32upx;
					color: #434343;

					.label {
						width: 130upx;
					}
				}
			}

			.testing-wrapper {
				margin: 20upx;
				border-top: 1upx dashed #cecece;
				padding: 0 10upx 10upx 10upx;

				.testing-title {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 20upx;
					color: #434343;
					font-size: 32upx;
				}

				.images-wrapper {
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					margin-top: 20upx;

					.reject-image {
						position: relative;
						width: 31%;
						height: 206upx;
						border-radius: 20upx;
						overflow: hidden;
						margin-left: 2%;
						margin-bottom: 20upx;
					}
				}
			}
		}
	}
</style>
